$import( "SmitearWebGL.Objects.Parser.Collada.DaeEntity" );
$import( "SmitearWebGL.Objects.Parser.Collada.DaeInput" );

SmitearWebGL.Objects.Parser.Collada.DaeSpline = SmitearWebGL.Objects.Parser.Collada.DaeEntity.extend(
{
	/******** constructor ********/

	init : function( document, node )
	{
		this.vertices = null;
		this.closed = null;

		this._super( document, node );
		this._registClass( "SmitearWebGL.Objects.Parser.Collada.DaeSpline" );
	}
	,
	read : function( node )
	{
		$THROW( node.localName == SmitearWebGL.Objects.Parser.Collada.Const.DAE_SPLINE_ELEMENT,
		"expected a '" + SmitearWebGL.Objects.Parser.Collada.Const.DAE_SPLINE_ELEMENT + "' element" );

		this._super( node );

		this.closed = this.getAttribute(node,SmitearWebGL.Objects.Parser.Collada.Const.DAE_CLOSED_ATTRIBUTE)  == "true" ? true : false;

		var sourceList = this.getNodeList( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_SOURCE_ELEMENT );
		$THROW( sourceList.length > 0, "<spline> requires at least one <source> element!" );

		var cvsNode = this.getNode( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_CONTROL_VERTICES_ELEMENT );
		$THROW( cvsNode, "<spline> requires exactly one <control_vertices> element!" );

		var inputList = this.getNodeList( cvsNode, SmitearWebGL.Objects.Parser.Collada.Const.DAE_INPUT_ELEMENT );
		var input;
		var sourceNode;
		var source;

		for( var i = 0; i < inputList.length; i++ )
		{
			input = new SmitearWebGL.Objects.Parser.Collada.DaeInput( this.document, inputList[i] );

			switch( input.semantic )
			{
				// The position of the control vertex
				case "POSITION":
					sourceNode = getNodeById( node, SmitearWebGL.Objects.Parser.Collada.Const.DAE_SOURCE_ELEMENT, input.source);
					$THROW( sourceNode, "source with id=" + input.source + " not found!" );
					
					source = new SmitearWebGL.Objects.Parser.Collada.DaeSource( this.document, sourceNode[0] );
					this.vertices = source.values;
					break;

				// The type of polynomial interpolation to represent the segment
				// starting at the CV. Common-profile types are:
				// LINEAR, BEZIER, HERMITE, CARDINAL, BSPLINE, STEP, and
				// NURBS
				case "INTERPOLATION":
					break;

				// The tangent that controls the shape of the segment preceding the
				// CV (BEZIER and HERMITE)
				case "IN_TANGENT":
					break;

				// The tangent that controls the shape of the segment following the
				// CV (BEZIER and HERMITE)
				case "OUT_TANGENT":
					break;

				// Defines the continuity constraint at the CV.
				// The common-profile types are: C0, C1, G1
				case "CONTINUITY":
					break;

				// The number of piece-wise linear approximation steps to use for
				// the spline segment that follows this CV
				case "LINEAR_STEPS":
					break;

				default:
					break;
			}
		}
	}
}
);